/* rcshgwsq.p - SHIPPER GATEWAY SEQUENCE SCHEDULE CREATE ABSS_DET       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*V8:ConvertMode=NoConvert                                              */
/*V8:RunMode=Character,Windows                                          */
/* REVISION: 9.1   CREATED       : 09/24/99     BY: *N003* Steve Nugent */
/* REVISION: 9.1  MODIFIED       : 08/12/00     BY: *N0KP* myb          */


/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
          {mfdeclre.i}

 /* ********** Begin Translatable Strings Definitions ********** */

 /* ********** End Translatable Strings Definitions ********** */

          {rcshgw.i} /* SHARED VARIABLES */

          define input parameter abs_recid as recid no-undo.
          define input parameter v_ship_to like so_ship no-undo.
          define output parameter errors like mfc_logical initial no no-undo.

          if ship_veh_ref = "" then do:
             {mfmsg.i 3404 4} /* NO VEHICLE REF NUMBER SPECIFIED */
             assign
                error_msg = error_msg + 1
                errors = yes.
             leave.
          end.

          for first abs_mstr where recid(abs_mstr) = abs_recid
          exclusive-lock: end.

          for first rcs_mstr where
                    rcs_shipfrom = ship_from    and
                    rcs_shipto   = v_ship_to    and
                    rcs_active no-lock:
          end.
          if cust_seq <> "" then do:
             for first rcsd_det where
                       rcsd_shipfrom  = ship_from     and
                       rcsd_shipto    = v_ship_to     and
                       rcsd_rlse_id   = rcs_rlse_id   and
                       rcsd_cust_po   = ship_cust_po  and
                       rcsd_cust_job  = cust_job      and
                       rcsd_cust_seq  = cust_seq      and
                       rcsd_part      = ship_part     and
                       rcsd_cust_ref  = ship_veh_ref  and
                       rcsd_dock      = cust_dock     and
                       rcsd_line_feed = line_feed     and
                       rcsd_status    = seq_status    and
                       (not rcsd_picked)              and
                       (not rcsd_delete)              and
                       (not rcsd_x_referenced)  exclusive-lock:
             end.

             if available rcsd_det then do:

                run create_abss_det in THIS-PROCEDURE
                    (input abs_mstr.abs_id, input recid(rcsd_det),
                     input ship_parent).

             end. /* IF AVAILABLE rcsd_det */
             else do:
                  {mfmsg.i 3387 4}
                  /* NO SEQUENCES FOUND */
                  assign
                    error_msg = error_msg + 1
                    errors = yes.
                  leave.
             end.

          end. /* IF cust_seq <> "" */

          else do:
               for first so_mstr where
                         so_nbr = ship_order no-lock:
               end.

               if available so_mstr and so_seq_order then do:
                    for first rcsd_det where
                              rcsd_shipfrom = ship_from     and
                              rcsd_shipto   = v_ship_to     and
                              rcsd_rlse_id  = rcs_rlse_id   and
                              rcsd_part     = ship_part     and
                              rcsd_cust_po  = ship_cust_po  and
                              rcsd_cust_ref = ship_veh_ref  and
                              rcsd_status   = seq_status    and
                              (not rcsd_picked)             and
                              (not rcsd_delete)             and
                              (not rcsd_x_referenced) exclusive-lock:
                    end.
                    if available rcsd_det then do:

                       run create_abss_det in THIS-PROCEDURE
                           (input abs_mstr.abs_id, input recid(rcsd_det),
                            input ship_parent).

                    end. /* IF AVAILABLE rcsd_det */
                    else do:
                         {mfmsg.i 3387 4}
                         /* NO SEQUENCES FOUND */
                         assign
                           error_msg = error_msg + 1
                           errors = yes.
                         leave.
                    end. /* else do: */
               end. /* IF AVAILABLE so_mstr ... */
          end. /* ELSE DO */

       /*PROCEDURE TO CREATE abss_det RECORDS FOR SEQUENCE SCHEDULES*/
       procedure create_abss_det:

          define input parameter id_abs like abs_id no-undo.
          define input parameter rcsd_recid as recid no-undo.
          define input parameter ship_parent like abs_par_id no-undo.

          for first rcsd_det where recid(rcsd_det) = rcsd_recid
          exclusive-lock: end.

          create abss_det.

             assign
                abss_abs_id     = id_abs
                abss_shipfrom   = rcsd_shipfrom
                abss_shipto     = rcsd_shipto
                abss_rlse_id    = rcsd_rlse_id
                abss_cust_job   = rcsd_cust_job
                abss_cust_seq   = rcsd_cust_seq
                abss_part       = rcsd_part
                abss_order      = rcsd_order
                abss_line       = rcsd_line
                abss_qty        = rcsd_discr_qty
                abss_date       = rcsd_date
                abss_time       = rcsd_time
                abss_cust_ref   = rcsd_cust_ref
                abss_dock       = rcsd_dock
                abss_line_feed  = rcsd_line_feed
                abss_status     = rcsd_status
                abss_ship_id    = ship_parent
                abss_mod_userid = global_userid
                abss_mod_date   = today
                abss_mod_pgm    = program-name(1)
                .

                if recid(abss_det) = -1 then.

                assign
                  rcsd_picked = yes
                  rcsd_mod_userid = global_userid
                  rcsd_mod_date = today
                  rcsd_mod_pgm = program-name(1)
                  .
       END PROCEDURE.
